package com.xkdx.guangguang.fragment.shopinfo;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

import com.xkdx.guangguang.module.network.AbsModule;
import com.xkdx.guangguang.shareclass.DiscountInfo;

public class ShopInfoNewsModule extends AbsModule {
	public List<DiscountInfo> newInfoList;

	@Override
	public void parseData() throws Exception {
		try {
			backJson = (JSONArray) result;

			for (int i = 0; i < backJson.length(); i++) {
				jsonObj = (JSONObject) backJson.get(i);
				String sortOfAct = jsonObj.getString("Act");
				if (sortOfAct.equals("getInfoListByShop")) {
					newInfoList = parseDiscountInfo(jsonObj.getJSONObject("Content"));
				}

			}
		} catch (Exception e) {
			// to do define a exception include all parseException
			throw e;
		}

	}

	private List<DiscountInfo> parseDiscountInfo(JSONObject person) throws Exception {
		List<DiscountInfo> list = new ArrayList<DiscountInfo>();

		try {
			JSONObject stut = (JSONObject) person.get("Result");
			JSONArray ListInfo = (JSONArray) stut.getJSONArray("ListInfo");
			JSONObject time = stut.getJSONObject("DetailInfo");
			for (int i = 0; i < ListInfo.length(); i++) {
				JSONObject jsonObj = ((JSONObject) ListInfo.opt(i));
				DiscountInfo discountInfo = new DiscountInfo();
				discountInfo.setInfoID(jsonObj.getString("InfoID"));
				discountInfo.setInfoTitle(jsonObj.getString("InfoTitle"));
				discountInfo.setInfoType(jsonObj.getString("InfoType"));
				discountInfo.setBeginTime(jsonObj.getString("BeginTime"));
				discountInfo.setEndTime(jsonObj.getString("EndTime"));
				discountInfo.setPictrueUrl(jsonObj.getString("PictureUrl"));
				list.add(discountInfo);
			}

		} catch (Exception e) {
			throw e;
		}

		return list;

	}

}
